//
//  GoodsTableViewCell.m
//  AppleCilent
//
//  Created by Nail Sharipov on 05/04/14.
//  Copyright (c) 2014 Nail Sharipov. All rights reserved.
//

#import "GoodsTableViewCell.h"


@implementation GoodsTableViewCell
{
    GoodsDomain* goods;
}
+ (float) getHeight
{
    return 100.0f;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        CGRect rect = [self frame];
        float height = [GoodsTableViewCell getHeight];
        float width = rect.size.width;
        float margin = 8.0f;
        
        float x = margin;
        float y = margin;
        
        float imageSize = height - 2.0f*margin;
        float priceSize = 0.8f*imageSize;
        float textSize = width - (imageSize + priceSize + (2.0f + 1.6f) * margin);
        
        self.image = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, imageSize, imageSize)];
        [self addSubview:self.image];
        
        x = x + imageSize + 0.8f * margin;
        
        self.name = [[UILabel alloc] initWithFrame:CGRectMake(x, y, textSize, 0.3f * imageSize)];
        [self.name setTextColor: [UIColor blackColor]];
        [self.name setBackgroundColor:[UIColor clearColor]];
        [self.name setAdjustsFontSizeToFitWidth:NO];
        [self.name setAdjustsLetterSpacingToFitWidth:NO];
        [self.name setTextAlignment:NSTextAlignmentLeft];
        [self.name setFont: [UIFont boldSystemFontOfSize: 16.0f]];
        [self addSubview:self.name];
        
        self.price = [[UILabel alloc] initWithFrame:CGRectMake(x + textSize, y, priceSize, 0.3f * imageSize)];
        [self.price setTextColor: [UIColor blackColor]];
        [self.price setBackgroundColor:[UIColor clearColor]];
        [self.price setAdjustsFontSizeToFitWidth:NO];
        [self.price setAdjustsLetterSpacingToFitWidth:NO];
        [self.price setTextAlignment:NSTextAlignmentLeft];
        [self.price setFont: [UIFont boldSystemFontOfSize: 16.0f]];
        [self addSubview:self.price];

        self.description = [[UITextView alloc] initWithFrame:CGRectMake(x, y + 0.3f * imageSize, textSize, 0.7f * imageSize)];
        [self.description setTextColor: [UIColor blackColor]];
        [self.description setBackgroundColor:[UIColor clearColor]];
        [self.description setScrollEnabled:NO];
        [self.description setEditable:NO];
        [self.description setUserInteractionEnabled:NO];
        [self.description setTextAlignment:NSTextAlignmentLeft];
        [self.description setFont: [UIFont systemFontOfSize: 10.0f]];
        [self addSubview:self.description];

    }
    return self;
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void) setGoods:(GoodsDomain*) goodsDomain
{
    goods = goodsDomain;
}

- (GoodsDomain*) getGoods
{
    return goods;
}


@end
